$(function(){
	$(document).on('click', '#suppiler-server', function(){
		var self = this;
		var suppiler_type = $(this).prev().find('select option:selected').val();
		$.ajax({
			type: "GET",
            url: "/datas/suppiler.json",
//        	data: {
//        		"suppiler_type": suppiler_type
//        	},
            dataType:"json",
            success:function(res){
    			var data = res.data;
    			var content = "";
    			for(var i in data){
    				content += '<div class="supplier-list">'+
							'<table class="layui-table supplier-table">'+
								'<tr>'+
									'<th>基本信息</th>'+
									'<th>预购数量</th>'+
									'<th>推荐供应商</th>'+
									'<th>推荐物流商</th>'+
									'<th></th>'+
								'</tr>'+
								'<tr>'+
									'<td>'+
										'<ul class="baseInfo">'+
											'<li class="layui-elip">大类：<span class="detail-tips-hover">' + data[i].material.bigType +'<span></li>'+
											'<li class="layui-elip">物料编号：<span class="detail-tips-hover">' + data[i].material.materialId +'<span></li>'+
											'<li class="layui-elip">物料名称：<span class="detail-tips-hover">' + data[i].material.materialName +'<span></li>'+
											'<li class="layui-elip">中类：<span class="detail-tips-hover">' + data[i].material.middleType +'<span></li>'+
											'<li class="layui-elip">型号：<span class="detail-tips-hover">' + data[i].material.model +'<span></li>'+
											'<li class="layui-elip">规格：<span class="detail-tips-hover">' + data[i].material.standard +'<span></li>'+
											'<li class="layui-elip">材质：<span class="detail-tips-hover">' + data[i].material.texture +'<span></li>'+
											'<li class="layui-elip">单位：<span class="detail-tips-hover">' + data[i].material.unit +'<span></li>'+
											'<li class="layui-elip">善筑模块化构部件 ：<span class="detail-tips-hover">' + data[i].material.useType +'<span></li>'+
											'<li class="layui-elip">体积：<span class="detail-tips-hover">' + data[i].material.volume +'<span></li>'+
											'<li class="layui-elip">重量：<span class="detail-tips-hover">' + data[i].material.weight +'<span></li>'+
											'<li class="layui-elip">子项目编号：<span class="detail-tips-hover">' + data[i].project.constProjectId +'<span></li>'+
											'<li class="layui-elip">子项目名：<span class="detail-tips-hover">' + data[i].project.constProjectName +'<span></li>'+
											'<li class="layui-elip">子项目地址：<span class="detail-tips-hover">' + data[i].project.projectAddress +'<span></li>'+
											'<li class="layui-elip">项目编号：<span class="detail-tips-hover">' + data[i].project.projectId +'<span></li>'+
											'<li class="layui-elip">项目名称：<span class="detail-tips-hover">' + data[i].project.projectName +'<span></li>'+
										'</ul>'+
									'</td>'+
									'<td align="center" width="72">'+
										'<div class="preOrderNum">'+
											'<input type="number" class="orderNum" min="1" value="' + data[i].buyNum+ '" data-originalnum="' + data[i].buyNum+ '">'+
										'</div>'+
									'</td>'+
									'<td align="center">'+
										'<section class="supplier-company">'+
											'<div class="company-name">' + data[i].supplierName+ '<span class="order-state">更改</span></div>'+
											'<div class="score">' + data[i].spIndicCount+ '分</div>'+
										'</section>'+
									'</td>'+
									'<td align="center">'+
										'<section class="supplier-company">'+
											'<div class="company-name">' + data[i].logisticsName+ '<span class="order-state">更改</span></div>'+
											'<div class="score">' + data[i].logIndicCount+ '分</div>'+
										'</section>'+
									'</td>'+
									'<td align="center" width="48">'+
										'<button class="layui-btn layui-btn-self layui-btn-small">发 送</button>'+
									'</td>'+
								'</tr>'+
							'</table>'+
						'</div>';
    			}
    			$("#suppiler-table-content").html(content);
			}
			
		});
	});
	
	//验证预购数量(大于0不能为空的整数)
	$("#suppiler-table-content").on("keypress", ".orderNum", function(e){
        $(this).val($(this).val().replace(/[^\d]/g, ''));//如果输入的不是数字用空字符替换
	}).on("blur", ".orderNum", function(){
		var inpVal = $(this).val();
		var originalnum = $(this).data("originalnum");
		if(inpVal == 0 || inpVal == ""){
			$(this).val(originalnum);
		}
	})
});